package com.lipaluma.example.clients.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="t_invoice")
@NamedQueries({
	@NamedQuery(name="Invoices.findForEcheance", query="SELECT OBJECT(inv) FROM Invoice inv WHERE inv.echeanceDate between :start and :end"),
	@NamedQuery(name="Invoices.findForAccount", query="SELECT OBJECT(inv) FROM Invoice inv WHERE inv.account = :id")
})
public class Invoice {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	@ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
	private Account account;
	
	@OneToMany
	@JoinColumn(name="invoice_id")
	private List<Order> orders;
	private double amountHT;
	private double amountTTC;
	@Temporal(TemporalType.DATE)
	private Date echeanceDate;
	private Date creationDate;
	
	public Date getEcheanceDate() {
		return echeanceDate;
	}
	public void setEcheanceDate(Date echeanceDate) {
		this.echeanceDate = echeanceDate;
	}
	public Date getCreationDate() {
		return creationDate;
	}
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public List<Order> getOrders() {
		return orders;
	}
	public void setOrders(List<Order> orders) {
		this.orders = orders;
	}
	public double getAmountHT() {
		return amountHT;
	}
	public void setAmountHT(double amountHT) {
		this.amountHT = amountHT;
	}
	public double getAmountTTC() {
		return amountTTC;
	}
	public void setAmountTTC(double amountTTC) {
		this.amountTTC = amountTTC;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
}
